package search;

/**
 * Created by chucun on 2016/5/31.
 */
public class BinarySearch {
    public static int indexOf(int[] a, int key) {
        int start = 0;
        int end = a.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            if (key < a[mid]) end = mid - 1;
            else if (key > a[mid]) start = mid + 1;
            else return mid;
        }
        return -1;

    }
}
